<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px">
      <el-breadcrumb-item :to="{ path: '/' }">后台管理</el-breadcrumb-item>
      <el-breadcrumb-item>学生管理</el-breadcrumb-item>
      <el-breadcrumb-item>录入退学学生</el-breadcrumb-item>
    </el-breadcrumb>
<el-divider></el-divider>
    <el-card style="width: 600px;height: 1130px;margin: 0 auto;border: 1px solid black"><!--卡片-->
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="130px" class="demo-ruleForm">
      <el-form-item label="学生姓名" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item label="原因" prop="cause">
        <el-input v-model="ruleForm.cause"></el-input>
      </el-form-item>
      <el-form-item label="剩余学费" prop="tuition">
        <el-input v-model="ruleForm.tuition"></el-input>
      </el-form-item>
      <el-form-item label="奖惩名" prop="Aname">
        <el-input v-model="ruleForm.Aname"></el-input>
      </el-form-item>
      <el-form-item label="奖惩方案" prop="Aproject">
        <el-input v-model="ruleForm.Aproject"></el-input>
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input v-model="ruleForm.address"></el-input>
      </el-form-item>
      <el-form-item label="退学时间:" prop="created">
        <el-date-picker
                v-model="ruleForm.created"
                type="date"
                placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
<!--      <el-form-item label="上传退学学生头像:">-->
<!--        &lt;!&ndash;当上传成功后调用handleSuccess这个方法&ndash;&gt;-->
<!--        <el-upload-->
<!--                action="http://localhost:9801/dropStudents/upload"-->
<!--                name="pic"-->
<!--                list-type="picture-card"-->
<!--                :on-success="handleSuccess"-->
<!--                :on-preview="handlePictureCardPreview"-->
<!--                :on-remove="handleRemove">-->
<!--          <i class="el-icon-plus"></i>-->
<!--        </el-upload>-->
<!--        <el-dialog :visible.sync="dialogVisible">-->
<!--          <img width="100%" :src="dialogImageUrl" alt="">-->
<!--        </el-dialog>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">添加</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
    </el-card>
  </div>
</template>


<script>
export default {
  data() {
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      ruleForm: {
        name: '',
        cause: "",
        tuition: "",
        url:'',
        Aname:'',
        Aproject:'',
        address: "",
        created: ""
      },
      rules: {
        name: [
          {required: true, message: '请输入学生姓名', trigger: 'blur'},
          {min: 2, max: 15, message: '长度在 2 到 15 个字符', trigger: 'blur'}
        ],
        cause: [
          {required: true, message: '请输入原因', trigger: 'blur'},
          { max: 50, message: '长度在 50 个字符', trigger: 'blur'}
        ],
        address: [
          {required: true, message: '请输入地址', trigger: 'blur'},
          { max: 50, message: '长度在 50 个字符', trigger: 'blur'}
          ]
      }
    };
  },
  methods: {
    // handleSuccess(response,file,fileList){
    //   //response代表服务器响应的图片路径
    //
    //   this.ruleForm.url = response;
    // },
    // handlePictureCardPreview(file) {
    //   this.dialogImageUrl = file.url;
    //   this.dialogVisible = true;
    // },
    // handleRemove(file, fileList) {
    //   console.log(file, fileList);
    //   //发出删除图片的请求
    //   axios.get("/remove?url="+v.p.url).then(function () {
    //     this.$message("服务器图片删除完成");
    //     this.ruleForm.url="";
    //   })
    // },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = 'http://localhost:9801/dropStudents/add-new';
          console.log('url = ' + url);
          let formData = this.qs.stringify(this.ruleForm);
          console.log('formData = ' + formData);
          // if (this.ruleForm.url == '') {
          //   this.ruleForm.$message.error("请选择上传的图片!")
          //   return;
          // }
          this.axios
                  .post(url,formData).then((response) => {
            let responseBody = response.data;
            if (responseBody.state == 20000) {
              this.$message({
                message: '添加成功！',
                type: 'success'
              });
              this.resetForm(formName);
            } else {
              this.$message.error(responseBody.message);
            }
          });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  mounted() {
    // window.onbeforeunload = function () {
    //   console.log("执行了删除");
    //   if (this.ruleForm.url != "") {
    //     //发出删除图片请求
    //     axios.get("/remove?url=" + this.ruleForm.url).then(function () {
    //       this.ruleForm.$message("服务器图片删除完成");
    //       this.ruleForm.url = "";
    //     })
    //   }
    // }
  }
}
</script>